import { ProFormOptions } from '@/components/pro-form/type'
import useGetReceiveAssetList from '@/hooks/useGetReceiveAssetList'
import { Ref } from 'vue'
import { optionsType } from '~/types/form'
import { userInfoModel } from '@/api/model/userModel'
import { userInfo } from '~/types/user'

type Props = {
  handleType: Ref<'check' | 'detail' | ''>
  taskForm: Ref<any>
  userInfo: Ref<userInfo<userInfoModel>>
  orgOptions: Ref<any>
  orgLoading: Ref<boolean>
  isInAllocate: Ref<boolean>
  isInBorrow: Ref<boolean>
}

export const useFormOptionsList = ({
  handleType,
  taskForm,
  userInfo,
  orgOptions,
  orgLoading,
  isInAllocate,
  isInBorrow
}: Props) => {
  const { typeOptions, typeLoading } = useGetTypeList()
  const { budgetOptions, budgetLoading } = useGetBudgetList()
  const { fetchGetReceiveList, receiveOptions, receiveLoading } =
    useGetReceiveAssetList()
  const { warehouseOptions, warehouseLoading } = useGetWarehouseList()

  const budgetFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'budgetName',
        label: '预算名称',
        disabled: true
      },
      {
        formType: 'input',
        key: 'budgetCode',
        label: '预算编码',
        disabled: true
      },
      {
        formType: 'inputNumber',
        key: 'budgetAmount',
        min: 0,
        precision: 2,
        label: '预算金额',
        disabled: true
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'select',
        key: 'receiveType',
        label: '申请状态',
        options: useDictData('STATUS').value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveReason',
        label: '申请原因',
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: 'taskStatus',
        label: '审批意见',
        options: useDictData('STATUS_TASK').value,
        disabled: handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })

  const purchaseFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'purchaseName',
        label: '采购名称',
        disabled: true
      },
      {
        formType: 'input',
        key: 'purchaseCode',
        label: '采购编号',
        disabled: true
      },
      {
        formType: 'inputNumber',
        min: 0,
        precision: 2,
        key: 'purchaseAmount',
        label: '采购金额',
        disabled: true
      },
      {
        formType: 'inputNumber',
        min: 0,
        key: 'number',
        label: '采购数量',
        disabled: true
      },
      {
        formType: 'select',
        key: 'purchaseStatus',
        label: '采购状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'budgetId',
        label: '预算名称',
        options: budgetOptions.value,
        loading: budgetLoading.value,
        disabled: true
      },
      {
        formType: 'date',
        key: 'purchaseDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'select',
        key: 'purchaseTypeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'purchasePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'purchaseBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'input',
        key: 'purchaseReason',
        label: '申请原因',
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: 'taskStatus',
        label: '审批意见',
        options: useDictData('STATUS_TASK').value,
        disabled: handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })

  const receiveFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'receiveCode',
        label: '领用编码',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '领用人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'getBranch',
        label: '领用部门',
        disabled: true
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'input',
        key: 'getDate',
        label: '领用日期',
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: 'receiveType',
        label: '领用状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'typeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'receiveReason',
        label: '申请原因',
        rows: 1,
        gridItem: {
          span: 1
        },
        placeholder: '请输入申请原因',
        noRule: true,
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: 'taskStatus',
        label: '审批意见',
        options: useDictData('STATUS_TASK').value,
        disabled: handleType.value === 'detail'
      },
      {
        formType: 'select',
        key: 'assetCode',
        label: '分配资产',
        options: receiveOptions.value,
        loading: receiveLoading.value,
        placeholder: '请选择分配资产',
        visiable: taskForm.value.taskStatus === '2',
        disabled: handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })

  const scrapFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'scrapCode',
        label: '报废编号',
        disabled: true
      },
      {
        formType: 'input',
        key: 'assetCode',
        label: '资产编号',
        disabled: true
      },
      {
        formType: 'input',
        label: '资产名称',
        key: 'assetName',
        disabled: true
      },
      {
        formType: 'select',
        key: 'scrapType',
        label: '报废状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'scrapTypeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'input',
        key: 'scrapReason',
        label: '报废原因',
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        disabled: true,
        noRule: true
      },
      {
        formType: 'select',
        key: 'taskStatus',
        label: '审批意见',
        options: useDictData('STATUS_TASK').value,
        disabled: handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })
  const easterFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'easterCode',
        label: '复活编号',
        disabled: true
      },
      {
        formType: 'input',
        key: 'assetCode',
        label: '资产编号',
        disabled: true
      },
      {
        formType: 'input',
        label: '资产名称',
        key: 'assetName',
        disabled: true
      },
      {
        formType: 'select',
        key: 'easterType',
        label: '复活状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'easterTypeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'input',
        key: 'easterReason',
        label: '复活原因',
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        disabled: true,
        noRule: true
      },
      {
        formType: 'select',
        key: 'taskStatus',
        label: '审批意见',
        options: useDictData('STATUS_TASK').value,
        disabled: handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })

  const allocateFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'allocateName',
        label: '调拨名称',
        disabled: true
      },
      {
        formType: 'input',
        key: 'allocateCode',
        label: '调拨编号',
        disabled: true
      },
      {
        formType: 'input',
        key: 'assetCode',
        label: '资产编号',
        disabled: true
      },
      {
        formType: 'input',
        label: '资产名称',
        key: 'assetName',
        disabled: true
      },
      {
        formType: 'select',
        key: 'typeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveReason',
        label: '调拨原因',
        disabled: true
      },
      {
        formType: 'select',
        key: 'allocateInStatus',
        label: '调入状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'allocateOutStatus',
        label: '调出状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'select',
        key: 'warehouseId',
        label: '调入存储位置',
        options: warehouseOptions.value,
        loading: warehouseLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'allocateInBranch',
        label: '调入部门',
        disabled: true
      },
      {
        formType: 'select',
        key: 'allocateOutBranch',
        label: '调出部门',
        disabled: true
      },
      // {
      //   formType: 'input',
      //   key: 'receiveBranch',
      //   label: '申请部门',
      //   disabled: true
      // },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      // {
      //   formType: 'select',
      //   key: 'allocateType',
      //   label: '调拨类型',
      //   dictOptions: useDictData('ALLOCATE_TYPE').value,
      //   disabled: true
      // },
      {
        formType: 'input',
        label: '调入审核人',
        key: 'taskInPerson',
        noRule: true,
        disabled: true
      },
      {
        formType: 'input',
        label: '调出审核人',
        key: 'taskOutPerson',
        noRule: true,
        disabled: true
      },
      {
        formType: 'date',
        label: '调入审核日期',
        key: 'taskInDate',
        noRule: true,
        disabled: true
      },
      {
        formType: 'date',
        label: '调出审核日期',
        key: 'taskOutDate',
        noRule: true,
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        rows: 1,
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: handleType.value === 'check' ? 'taskInStatus' : 'allocateInStatus',
        label: '调入审批意见',
        options: useDictData('STATUS_TASK').value,
        noRule: !isInAllocate.value,
        disabled: !isInAllocate.value || handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'inReason',
        label: '调入批复',
        rows: 1,
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: !isInAllocate.value || handleType.value === 'detail'
      },
      {
        formType: 'select',
        key:
          handleType.value === 'check' ? 'taskOutStatus' : 'allocateOutStatus',
        label: '调出审批意见',
        options: useDictData('STATUS_TASK').value,
        noRule: isInAllocate.value,
        disabled: isInAllocate.value || handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'outReason',
        label: '调出批复',
        rows: 1,
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: isInAllocate.value || handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })

  const borrowFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'borrowName',
        label: '借用名称',
        disabled: true
      },
      {
        formType: 'input',
        key: 'borrowCode',
        label: '借用编号',
        disabled: true
      },
      {
        formType: 'input',
        key: 'assetCode',
        label: '资产编号',
        disabled: true
      },
      {
        formType: 'input',
        label: '资产名称',
        key: 'assetName',
        disabled: true
      },
      {
        formType: 'select',
        key: 'typeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveReason',
        label: '借用原因',
        disabled: true
      },
      {
        formType: 'select',
        key: 'borrowInStatus',
        label: '借入状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'select',
        key: 'borrowOutStatus',
        label: '借出状态',
        disabled: true,
        options: useDictData('STATUS').value
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'borrowInBranch',
        label: '借入部门',
        disabled: true
      },
      {
        formType: 'select',
        key: 'borrowOutBranch',
        label: '借出部门',
        disabled: true
      },
      // {
      //   formType: 'input',
      //   key: 'receiveBranch',
      //   label: '申请部门',
      //   disabled: true
      // },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      // {
      //   formType: 'select',
      //   key: 'borrowType',
      //   label: '借用类型',
      //   dictOptions: useDictData('ALLOCATE_TYPE').value,
      //   disabled: true
      // },
      {
        formType: 'input',
        label: '借入审核人',
        key: 'taskInPerson',
        noRule: true,
        disabled: true
      },
      {
        formType: 'input',
        label: '借出审核人',
        key: 'taskOutPerson',
        noRule: true,
        disabled: true
      },
      {
        formType: 'date',
        label: '借入审核日期',
        key: 'taskInDate',
        noRule: true,
        disabled: true
      },
      {
        formType: 'date',
        label: '借出审核日期',
        key: 'taskOutDate',
        noRule: true,
        disabled: true
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        rows: 1,
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true,
        disabled: true
      },
      {
        formType: 'select',
        key: handleType.value === 'check' ? 'taskInStatus' : 'borrowInStatus',
        label: '借入审批意见',
        options: useDictData('STATUS_TASK').value,
        noRule: !isInBorrow.value,
        disabled: !isInBorrow.value || handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'inReason',
        label: '借入批复',
        rows: 1,
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: !isInBorrow.value || handleType.value === 'detail'
      },
      {
        formType: 'select',
        key: handleType.value === 'check' ? 'taskOutStatus' : 'borrowOutStatus',
        label: '借出审批意见',
        options: useDictData('STATUS_TASK').value,
        noRule: isInBorrow.value,
        disabled: isInBorrow.value || handleType.value === 'detail'
      },
      {
        formType: 'textarea',
        key: 'outReason',
        label: '借出批复',
        rows: 1,
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: isInBorrow.value || handleType.value === 'detail'
      }
    ] as optionsType
    return useSetOptions(list)
  })

  return {
    purchaseFormOptions,
    budgetFormOptions,
    receiveFormOptions,
    scrapFormOptions,
    easterFormOptions,
    allocateFormOptions,
    borrowFormOptions,
    fetchGetReceiveList
  }
}
